<?php

namespace app\admin\controller\fastchat;

use app\common\controller\Backend;
use app\admin\model\FastChatServiceUser;

class Serviceuser extends Backend
{
    /**
     * FastChatServiceUser模型对象
     * @var FastChatServiceUser
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new FastChatServiceUser();
        $this->view->assign("addSessiondataList", $this->model->getAddSessiondataList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->view->assign("onlineStatusList", $this->model->getOnlineStatusList());
    }


    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->with(['admin'])
                ->where($where)
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->with(['admin'])
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            foreach ($list as $row) {

                $row->getRelation('admin')->visible(['nickname']);
            }
            $list = collection($list)->toArray();
            return json(["total" => $total, "rows" => $list]);
        }
        return $this->view->fetch();
    }
}
